﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace ProjectNocturnalFool
{
    class BackgroundControl : UserControl
    {
        ParticleEngine engine;
        Texture2D bgTexture;
        Random rand;

        /// <summary>
        /// Loads Content of button
        /// </summary>
        public override void LoadContent()
        {
            base.LoadContent();
            rand = new Random(DateTime.Now.GetHashCode());

            List<Texture2D> texList = new List<Texture2D>();
            texList.Add(TacticsGame.Instance.Content.Load<Texture2D>("Particles/Star"));
            bgTexture = TacticsGame.Instance.Content.Load<Texture2D>(Constants.TitleBackground);
            
            engine = new ParticleEngine(texList);            

            width = VirtualScreen.Instance.VirtualWidth;
            height = VirtualScreen.Instance.VirtualHeight;
        }

        /// <summary>
        /// Updates logic based on mouse
        /// </summary>
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            engine.GenerateNewFallingParticle();
            engine.Update();
        }

        /// <summary>
        /// Draws button based on location
        /// </summary>
        /// <param name="gameTime">gameTime since last draw</param>
        public override void Draw(GameTime gameTime)
        {
            TacticsGame.Instance.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone);

            Rectangle targetRect = new Rectangle(x, y, width, height);
            Vector2 something = new Vector2(x, y);

            TacticsGame.Instance.spriteBatch.Draw(bgTexture, something, null, Color.White, 0, Vector2.Zero,1.0f, SpriteEffects.None, 0.0f);            

            TacticsGame.Instance.spriteBatch.End();

            engine.Draw();
        }


    }
}
